<%--
 *  File:   DefaultTaskEdit.jsp
 *  Author: David Zhang 
 *  Date:   2002/02/19
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //Initial parameters.
  Category cat = Category.getInstance("jsp.DefaultTaskEdit"); 
  String strModuleName = "BIEE";  
  String strTableName = "ovdefaulttask";
	String privilegeCode = "Z0704,L601"; 
	String contextPath = request.getContextPath();
%>



<%
  //Get userinfo from session.
  HashMap mapUserInfo = (HashMap) session.getAttribute("userinfo");
  String orgid = mapUserInfo.get("orgid").toString();
%>

<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>

<html>
<head>
<title>DefaultTaskEdit</title>
<PageFlow:CheckPageFlow pageName="defaulttaskedit"/>
<%@ include file="/inc/InitEdit.inc" %>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
  <script language="JavaScript" src="../js/FuncLib.js"></script>

<%
  HashMap defaulttaskinfo = (HashMap) pageContext.getAttribute("defaulttaskinfo");
  //System.out.println(defaulttaskinfo);
  String strIsNew = "no";
  Vector allcontactroletype = (Vector) pageContext.getAttribute("allcontactroletype");
  Vector allintervaltypename = (Vector) pageContext.getAttribute("allintervaltypename");
  if ( allcontactroletype == null )  allcontactroletype = new Vector();
  if ( allintervaltypename == null )  allintervaltypename = new Vector();  
  
  Vector allusername = (Vector) pageContext.getAttribute("allusername");
  Vector allusergroup = (Vector) pageContext.getAttribute("allusergroup");
  Vector user_usergroup_ids = new Vector();
  int position = 0;
  if ( allusername != null && allusername.size() > 0 )
  {
      for (int i = 0; i < allusername.size(); i++) 
      {
          HashMap temp = (HashMap) allusername.elementAt(i);
          HashMap map = new HashMap();
          map.put("value", temp.get("userid"));
          map.put("valuename", temp.get("username"));
          user_usergroup_ids.add(map);
          position++;
      }
  }
  if ( allusergroup != null && allusergroup.size() > 0 )
  {
      for (int i = 0; i < allusergroup.size(); i++) 
      {
          HashMap temp = (HashMap) allusergroup.elementAt(i);
          HashMap map = new HashMap();
          map.put("value", temp.get("usergroupid"));
          map.put("valuename", temp.get("usergroupname"));
          user_usergroup_ids.add(map);
      }
  }  

  String defaulttaskid = "";
  String sequence = "";
  String defaulttaskname = "";
  String defaulttaskdesc = "";
  
  String defaultperiodnum = "";
  String defaultintervaltype = "";
  String responsibilitytype = "";
  String responsibleentityid = ""; 
  String isdecisionmaker = ""; 
  String isdecisionmakerChecked = ""; 
  String isnecessary = ""; 
  String isusr = ""; 
  String isnecessaryChecked = ""; 
  String iscustomresponsible= "";
  String iscustomresponsibleChecked="";
  String isusrChecked="";
  Object obj;
  //Get the defaulttaskinfo to edit.
  if ( defaulttaskinfo == null || defaulttaskinfo.isEmpty() || defaulttaskinfo.get("defaulttaskid")==null)
  {
    if(defaulttaskinfo == null)
      defaulttaskinfo = new HashMap();
      strIsNew = "yes";
      defaultperiodnum = "7";
  }  
  //else
  //{
      if(defaulttaskinfo.get("defaulttaskid")!=null)
        defaulttaskid = (defaulttaskinfo.get("defaulttaskid")).toString();      
      if(defaulttaskinfo.get("sequence")!=null)
        sequence = (defaulttaskinfo.get("sequence")).toString();
      if(defaulttaskinfo.get("defaulttaskname")!=null)
        defaulttaskname = (defaulttaskinfo.get("defaulttaskname")).toString();
      if(defaulttaskinfo.get("iscustomresponsible")!=null)
        iscustomresponsible = (defaulttaskinfo.get("iscustomresponsible")).toString();

      obj = defaulttaskinfo.get("defaulttaskdesc");
      if ( obj != null )  defaulttaskdesc = obj.toString();
      obj = defaulttaskinfo.get("defaultperiodnum");
      if ( obj != null )  defaultperiodnum = obj.toString();      
      obj = defaulttaskinfo.get("defaultintervaltype");
      if ( obj != null )  defaultintervaltype = obj.toString();
      obj = defaulttaskinfo.get("responsibilitytype");
      if ( obj != null )  responsibilitytype = obj.toString();
      obj = defaulttaskinfo.get("responsibleentityid");
      if ( obj != null )  responsibleentityid = obj.toString();

      obj = defaulttaskinfo.get("isdecisionmaker");
      if ( obj != null )  isdecisionmaker = obj.toString();
      if ( isdecisionmaker != null && isdecisionmaker.equals("Y") ) 
          isdecisionmakerChecked = "checked";

               obj = defaulttaskinfo.get("iscustomresponsible");
      if ( obj != null )  iscustomresponsible = obj.toString();    
      if ( iscustomresponsible != null && iscustomresponsible.equals("Y") ) 
      	iscustomresponsibleChecked = "checked";
      
      obj = defaulttaskinfo.get("isnecessary");
      if ( obj != null )  isnecessary = obj.toString();    
      if ( isnecessary != null && isnecessary.equals("Y") ) 
          isnecessaryChecked = "checked";
      
      obj = defaulttaskinfo.get("isusr");
      if ( obj != null )  isusr = obj.toString();    
      if ( isusr != null && isusr.equals("Y") ) 
    	  isusrChecked = "checked";
      
  //}    
  
  cat.debug("The defaulttaskinfo is :" + defaulttaskinfo);
  cat.debug("The allusername is :" + allusername);    
  cat.debug("The allusergroup is :" + allusergroup);
  cat.debug("The allcontactroletype is :" + allcontactroletype);    
  cat.debug("The user_usergroup_ids is :" + user_usergroup_ids);
  cat.debug("The isdecisionmaker is :" + isdecisionmaker);
  cat.debug("The isnecessary is :" + isnecessary);
  cat.debug("The isusr is :" + isusr);
%>

<script language="JavaScript">
function check()
{
  var frm = document.defaulttaskeditform; 
  <%--[SCRIPT]  defaultperiodnum  [SCRIPT]--%>
  if ( isEmpty(frm.sequence.value) )
  {
      alert("<%= message.getMessage("A_Sequence")%>");
      return false;
  } 
  
  if ( ! isNumberic(frm.sequence.value) ) 
  {
      alert("<%= message.getMessage("A_NumberSequence")%>");
      return false;
  }   
  
  if ( isEmpty(frm.defaulttaskname.value) )
  {
      alert("<%= message.getMessage("A_DefTaskName")%>");
      return false;
  }  

    
    
  if ( isEmpty(frm.defaultperiodnum.value) )
  {
    alert('<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_DefaultPeriodNum",false)) %>');
    return false;
  } 
  
  
  
   if (defaulttaskeditform.iscustomresponsible0.checked &&  isEmpty(frm.customtype.value) )
  {
    alert('<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_CustomeRespType",false)) %>');
    return false;
  } 
  
   
  if (!isNumberic(frm.defaultperiodnum.value))
  {
    alert('<%=message.getMessageDesc("VALUE_MUST_BE_NUMBER",label.getLabelName("L_DefaultPeriodNum",false)) %>');
    return false;
  }
  if (frm.defaultperiodnum.value-0<=0)
  {
    alert('<%=message.getMessageDesc("VALUE_MUST_BE_POSITIVE",label.getLabelName("L_DefaultPeriodNum",false)) %>');
    return false;
  }
     
  <%--[SCRIPT]  The "sequence" must be unique.  [SCRIPT]--%>
  var sequences = parent.up.defaulttasksummaryform.sequence;
  var taskids = parent.up.defaulttasksummaryform.taskid;
  
  if ( typeof(sequences) == "unundefined" )
  {
      if ( ! sequences.length > 0 )
      {
          <%--[SCRIPT]  alert(Number(sequences.value) + "/" + Number(frm.sequence.value));  [SCRIPT]--%>
          if ( typeof(frm.defaulttaskid) == "undefined" && Number(sequences.value) == Number(frm.sequence.value) )
          {
              alert("<%= message.getMessage("SERIAL_IS_EXIST")%>");
              return false;
          }
      }
      else
      {
          for (var i = 0; i <  sequences.length; i++)
          {
              if ( Number(sequences[i].value) == Number(frm.sequence.value) )
              {
                  if ( typeof(frm.defaulttaskid) != "undefined" && 
                       taskids[i].value == frm.defaulttaskid.value )
                  {
                      <%--[SCRIPT]  That is ok.  [SCRIPT]--%>
                  }
                  else
                  {     
                      alert("<%= message.getMessage("SERIAL_IS_EXIST")%>");
                      return false;
                  }
              }
          }
      }  
  }
  return true;
}

function save()
{
  var frm = document.defaulttaskeditform;
  if ( ! check() ) return;
  frm.actionname.value = "done";   
  isRunning = true;
  frm.submit();
}

function checkboxValue(checkboxName)
{
   var frm = document.defaulttaskeditform;
   var obj = eval("document.defaulttaskeditform." + checkboxName);
   if ( obj.value == "N" || obj.value == "" )  
   {
   obj.value = "Y"; 
   }
   else  
   {
   obj.value = "N";
   }
}

function checkboxValueCus(checkboxName)
{
   var frm = document.defaulttaskeditform;
   var obj = eval("document.defaulttaskeditform." + checkboxName);
   if ( obj.value == "N" || obj.value == "" )  
   {
   obj.value = "Y"; 
   page_isCustomClick();
   }
   else  {
   obj.value = "N";
   page_isCustomClick();
   }
}
function selectResponsibilityType()
{
   var frm = document.defaulttaskeditform;
   var position = frm.responsibleentityid.selectedIndex;
   if ( position < <%=JspHelper.filterNull( position )%> )  frm.responsibilitytype.value = "U";
   else  frm.responsibilitytype.value = "G";
   <%--[SCRIPT]  alert("frm.responsibilitytype.value=" + frm.responsibilitytype.value);  [SCRIPT]--%>
}
function page_orgchanged()
{
  var frm = document.defaulttaskeditform;
  frm.actionname.value = "reload";  
  frm.target="_self";
  isRunning = true;
  frm.submit();
}
function page_isCustomClick()
{
   //checkboxValue('iscustomresponsible');
  var isCustom=defaulttaskeditform.iscustomresponsible0.checked;
 
  if(isCustom)
  {
  
    //defaulttaskeditform.org4custom.disabled=false;
    defaulttaskeditform.finalTitle.disabled=false;
    defaulttaskeditform.customtype.disabled=false;
    tdCustTypeID.disabled=false;
    defaulttaskeditform.org4resp.disabled=true;
    defaulttaskeditform.responsibleentityid.disabled=true;
    tdRspEntity.disabled=true;
     page_customtypechg();
    }
  else
  {
   //defaulttaskeditform.org4custom.disabled=true;
    defaulttaskeditform.finalTitle.disabled=true;
    defaulttaskeditform.customtype.disabled=true;
     tdCustTypeID.disabled=true;
    defaulttaskeditform.org4resp.disabled=false;
    tdRspEntity.disabled=false;
    defaulttaskeditform.responsibleentityid.disabled=false;
    defaulttaskeditform.customtype.options[0].selected=true;
    tdFinalRspt.disabled=true;
    tdTitalName.disabled=true;
        defaulttaskeditform.deptid.disabled=true;
        defaulttaskeditform.deptorgid.disabled=true;
        defaulttaskeditform.deptTitle.disabled=true;
        
  }
 
}
  
function page_customtypechg()
{
   var customtype=defaulttaskeditform.customtype.options[defaulttaskeditform.customtype.selectedIndex].value;
   if(customtype==1)
   {
      defaulttaskeditform.finalTitle.disabled=false;
      tdFinalRspt.disabled=false;
      tdTitalName.disabled=true;
        defaulttaskeditform.deptid.disabled=true;
        defaulttaskeditform.deptorgid.disabled=true;
        defaulttaskeditform.deptTitle.disabled=true;
        
   }
   else
   {
     defaulttaskeditform.finalTitle.disabled=true;
     tdFinalRspt.disabled=true;
      tdTitalName.disabled=true;
        defaulttaskeditform.deptid.disabled=true;
        defaulttaskeditform.deptorgid.disabled=true;
        defaulttaskeditform.deptTitle.disabled=true;
        
     if(customtype==3)
     {
      
        
        tdTitalName.disabled=false;
        defaulttaskeditform.deptid.disabled=false;
        defaulttaskeditform.deptorgid.disabled=false;
        defaulttaskeditform.deptTitle.disabled=false;
        
     }
     
   }
}


function page_popwindow(blue)
{
  if (typeof popwindow != 'undefined') popwindow.close();
  popwindow = window.open("<%=contextPath%>/biee/EmployeeBussiseForPop.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>","newwindow", "height=300, width=800,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	
}

function setSalesMan(userid,username,orgname){
	document.defaulttaskeditform.userid.value=userid;
	document.defaulttaskeditform.orgname.value=orgname;
	document.defaulttaskeditform.username.value=username;
}


</script>
</head>

<body>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
  <form name="defaulttaskeditform" method="post" action="../Dispatcher" target="_parent">
  <input type="hidden" name="pagename" value="defaulttaskedit">
  <input type="hidden" name="actionname">  
  <input type="hidden" name="orgid" value="<%=JspHelper.filterNull( orgid )%>">                                   

  <% if ( ! defaulttaskinfo.isEmpty() && defaulttaskid!=null && responsibilitytype!=null &&  defaulttaskid.length()>0 && responsibilitytype.length()>0)
     { %>
  <input type="hidden" name="defaulttaskid" value="<%=JspHelper.filterNull( defaulttaskid )%>">
  <input type="hidden" name="responsibilitytype" value="<%=JspHelper.filterNull( responsibilitytype )%>"> 
  <% } 
     else
     { %>
  <input type="hidden" name="responsibilitytype" value="U">   
  <% } %>
  <input type="hidden" name="subjectcode" value="<%=JspHelper.filterNull( pageContext.getAttribute("subjectcode") )%>">    
  
  <input type="hidden" name="languagecode" value="<%= strLanguageCode %>">    
  <tr> 
    <td> 
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr><td colspan="2" class="summary_top"></td></tr>
        <tr> 
          <td colspan="2">
            <img src="../images/<%= strLanguageCode %>/quote.gif" width="16" height="11"> 
            <%= label.getLabelName("L_New/EditTask") + label.getLabelName("L_Colon") %>
          </td>
        </tr>
      </table>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
        <tr>  
          <td class="need" width="110">
            <%= label.getLabelName("L_Sequence") + label.getLabelName("L_Colon") %>
          </td>
          <td colspan="3"> 
            <input type="text" name="sequence" value="<%=JspHelper.filterNull( sequence )%>" size="10">
          </td>
        </tr>
        <tr>
          <td class="need">
            <%= label.getLabelName("L_DefaultTaskName") + label.getLabelName("L_Colon") %>
          </td>
          <td colspan="3">
            <input type="text" name="defaulttaskname" value="<%=JspHelper.filterNull( defaulttaskname )%>" size="60">
          </td>
        </tr>
        <tr> 
          <td class="td-text">
            <%= label.getLabelName("L_DefaultTaskDesc") + label.getLabelName("L_Colon") %>
          </td>
          <td colspan="3"> 
            <input type="text" name="defaulttaskdesc" value="<%=JspHelper.filterNull( defaulttaskdesc )%>" size="60">
          </td>
        </tr>
        <tr> 
          <td class="need"> 
            <%= label.getLabelName("L_DefaultPeriodNum") + label.getLabelName("L_Colon") %>
          </td>
          <td>
            <select name="defaultintervaltype">
              <logic:iterate id="allintervaltypename1" collection="<%= allintervaltypename %>">
              <% 
                 HashMap intervaltypename = (HashMap) pageContext.getAttribute("allintervaltypename1"); 
                 String valuename = (String) intervaltypename.get("valuename");
                 String value = intervaltypename.get("value").toString();
                 String strSelect = "";   
                 if ( defaulttaskinfo.get("defaultintervaltype") != null )
                 {
                     String existvalue = defaulttaskinfo.get("defaultintervaltype").toString(); 
                     if ( value.equals(existvalue) )  strSelect = "Selected";
                 }
              %>
              <option value="<%=JspHelper.filterNull( value )%>" <%=JspHelper.filterNull( strSelect )%>>  <%=JspHelper.filterNull( valuename )%></option>
              </logic:iterate>  
            </select> 
            <input type="text" name="defaultperiodnum" value="<%=JspHelper.filterNull( defaultperiodnum )%>" size="10">
          </td>

          <td class="td-text" id="tdRspEntity">
            <%= label.getLabelName("L_ResponsibleEntity") + label.getLabelName("L_Colon") %>
          </td>
          <% if ( strIsNew.equalsIgnoreCase("no") )
          { %>  
          <td>
            <custom:select  styleId="org4resp" property="userorgid" optionsName="allparentorgs" optionValueKey="orgid"  optionInnerTextKey="shortname" onchange="javascript:page_orgchanged();"/>
            <select name="responsibleentityid" onchange="javascript:selectResponsibilityType()">
              <% int position1 = 0; %>
              <logic:iterate id="user_usergroup_ids1" collection="<%= user_usergroup_ids %>">
              <% 
                 position1++;
                 HashMap user_usergroup_id = (HashMap) pageContext.getAttribute("user_usergroup_ids1"); 
                 String valuename = (String) user_usergroup_id.get("valuename");
                 String value = user_usergroup_id.get("value").toString();
                 String strSelect = ""; 
                 if ( defaulttaskinfo.get("responsibleentityid") != null )
                 {
                     String existvalue = defaulttaskinfo.get("responsibleentityid").toString(); 
                     if ( value.equals(existvalue) && 
                          ! (responsibilitytype.equalsIgnoreCase("G") && position1 <= position) &&
                          ! (responsibilitytype.equalsIgnoreCase("U") && position1 > position) 
                        )  strSelect = "Selected";
                 }
              %>
              <option value="<%=JspHelper.filterNull( value )%>" <%=JspHelper.filterNull( strSelect )%>>  <%=JspHelper.filterNull( valuename )%></option>
              </logic:iterate>  
            </select> 
          </td>
          <% }
          
          else
          { %>
         <td >
					<input type="hidden" name="userid"/>
		           	<input type="text" name="orgname"/>
		           	<input type="text" name="username"/>
              <a onclick="page_popwindow();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
          </td>
          <% } %> 

        </tr>
        <tr> 
          <td class="td-text">
            <%= label.getLabelName("L_IsDecisionMaker") + label.getLabelName("L_Colon") %>
          </td>
          <td>
            <input type="checkbox" name="isdecisionmaker0" <%=JspHelper.filterNull( isdecisionmakerChecked )%> class="normalradio"  
                   onclick="javascript:checkboxValue('isdecisionmaker')">
          </td>
          <% if ( strIsNew.equalsIgnoreCase("no") ) 
             { %>
              <input type="hidden" name="isdecisionmaker" value="<%=JspHelper.filterNull( isdecisionmaker )%>">
          <% }
             else
             { %>
              <input type="hidden" name="isdecisionmaker" value="N">
          <% } %>    
          
          <td class="td-text">
            <%= label.getLabelName("L_IsOptional") + label.getLabelName("L_Colon") %>
          </td>
          <td>
            <input type="checkbox" name="isnecessary0" <%=JspHelper.filterNull( isnecessaryChecked )%> class="normalradio"  
                   onclick="javascript:checkboxValue('isnecessary')">
          </td>
          <% if ( strIsNew.equalsIgnoreCase("no") ) 
             { %>
              <input type="hidden" name="isnecessary" value="<%=JspHelper.filterNull( isnecessary )%>">
          <% }
             else
             { %>
              <input type="hidden" name="isnecessary" value="N">
          <% } %>    
        </tr>
        
        <tr>
          <td class="td-text">
            <%= label.getLabelName("L_UsrNeed") + label.getLabelName("L_Colon") %>
          </td>
          <td>
            <input type="checkbox" name="isusr0" <%=JspHelper.filterNull( isusrChecked )%> class="normalradio"  
                   onclick="javascript:checkboxValue('isusr')">
          </td>
          <% if ( strIsNew.equalsIgnoreCase("no") ) 
             { %>
              <input type="hidden" name="isusr" value="<%=JspHelper.filterNull( isusr )%>">
          <% }
             else
             { %>
              <input type="hidden" name="isusr" value="N">
          <% } %> 
          
          
          
          
          
          
          
          
        <td class="td-text" ><%= label.getLabelName("L_IsCustomeResponsible") + label.getLabelName("L_Colon") %></td>
        <td >
            <input type="checkbox" name="iscustomresponsible0" <%=JspHelper.filterNull( iscustomresponsibleChecked )%> class="normalradio"  
                   onclick="javascript:checkboxValueCus('iscustomresponsible');">                   
        </td>
         <% if ( strIsNew.equalsIgnoreCase("no") ) 
             { %>
              <input type="hidden" name="iscustomresponsible" value="<%=JspHelper.filterNull( iscustomresponsible )%>">
          <% }
             else
             { %>
              <input type="hidden" name="iscustomresponsible" value="N">
          <% } %> 
          
        </tr>   
        <tr>
          <td class="td-text"  id="tdFinalRspt" disabled><%= label.getLabelName("L_FinalRespName") + label.getLabelName("L_Colon") %></td>
        
          <td>
            <custom:selectdic styleId="finalTitle" disabled="true"  defaultValueCost=" " defaultValue="------"  name="defaulttaskinfo" property="jobtital" dictType="JobTitle"/>
          </td>
         
         <td class="need" id="tdCustTypeID" disabled><%= label.getLabelName("L_CustomeRespType") + label.getLabelName("L_Colon") %></td>
        <td ><custom:selectdic defaultValueCost=" " defaultValue="------" disabled="true" name="defaulttaskinfo" property="customtype" dictType="CustomRestonibleType" onclick="javascript:page_customtypechg();"/></td>
            
        </tr>  
        <tr>
          <td class="td-text"  id="tdTitalName" disabled ><%= label.getLabelName("L_TitleName") + label.getLabelName("L_Colon") %></td>
        <td colspan="3">
          <custom:select  disabled="true"  property="deptorgid"  optionsName="allparentorgs" optionValueKey="orgid"  optionInnerTextKey="shortname" onchange="javascript:page_deptorgchanged();"/>
          <custom:select  disabled="true" name="defaulttaskinfo" property="deptid"  optionsName="alldepts" optionValueKey="deptid"  optionInnerTextKey="deptname" />
          
          <custom:selectdic  styleId="deptTitle" disabled="true"    name="defaulttaskinfo" property="jobtital" dictType="JobTitle"/>
         </td>     
        </tr>
      </table>
    </td>
  </tr>
  <tr><td class="summary_top"></td></tr>
  <tr> 
    <td class="td_center"><a onclick="save()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a></td>
  </tr>
</form>
</table>
</body>
<script  language="JavaScript">
  page_isCustomClick();
</script>

</html>


